<html>
    <head>
        <title>C12TDT Works</title>
        <link href="public/css/style_web2.css" rel="stylesheet" type="text/css">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="public/jc/jquery-1.2.6.min.js"></script>
        <script type="text/javascript">
            function slideSwitch() {
                var $active = $('#baner IMG.active');

                if ($active.length == 0)
                    $active = $('#baner IMG:last');

                // use this to pull the images in the order they appear in the markup
                var $next = $active.next().length ? $active.next()
                        : $('#baner IMG:first');
                $active.addClass('last-active');

                $next.css({opacity: 0.0})
                        .addClass('active')
                        .animate({opacity: 1.0}, 1000, function() {
                    $active.removeClass('active last-active');
                });
            }
            $(function() {
                setInterval("slideSwitch()", 2000);
            });
        </script>
    </head>
    <body>
        <div id="wrapper">

            <?php
            require_once './model/works.php';
            $keyword = new Works();
            $keyword->table_name = "works";
            ?>
            <?php
            if (!isset($_GET["page"]))
                $page = 1;
            else
                $page = $_GET["page"];
            $total = $keyword->countWords();
            $work = $keyword->selects(null, $_GET['id']);
            ?>
            <div id="sum">
                <div id="baner">
                    <img src="public/image/5-1394604835.jpg" alt="" class="active"/>
                    <img src="public/image/logo_2-1394601748.jpg" alt=""  />
                    <img src="public/image/1-1394604824.jpg" alt=""  />
                    <img src="public/image/2-1394604827.jpg" alt=""  />
                    <img src="public/image/3-1394604829.jpg" alt=""  />
                    <img src="public/image/4-1394604832.jpg" alt=""  />
                </div>
                <div id="boder"></div>
                <header>
                    <div class="logo">
                        <h1><b class="Works">C12TDT</b> Works</h1>
                        <p class="text_td">Thu Duc College of Tehnology</p>
                    </div>
                    <div id="boders"></div>
                    <div id="col_left">
                        <h4>Hôm nay  <?php echo date("m/d/Y"); ?></h4>
                        <p class="main_menu">
                        <h3>MAIN MENU</h3>
                        <div id="boder_menu"></div>
                        </p>
                        <nav>
                            <ul>
                                <li><a href="index.php">HOME</a></li>
                                <li><a href="#">CONTENT TYPES</a></li>
                                <li><a href="#">FORUMS</a></li>
                                <li><a href="#">CONTACT</a></li>
                            </ul>
                        </nav>
                        <p class="main_menu">
                        <h3>USER LOGIN</h3>
                        <div id="boder_menu"></div>
                        </p>
                        <p>User name</p>
                        <input type="text" name="user_name">
                        <p>Password <strong>*</strong></p>
                        <input type="password" name="password"></br>
                        <p id="input_st"><a href="#">Log in</a></p>
                    </div>
                    <section>
                        <p class="main_menus">
                        <h3>CONTENT</h3>
                        <div id="boder_menus"></div>
                        </p>
                        <div id="edit">
                            <form method="post"      enctype="multipart/form-data">
                                <label for="file">Name:</label>
                                <input type="text"name="name" id="name" value="<?php echo $work['name']; ?>"><br>
                                <label for="file">Company:</label>
                                <input type="text" name="company" id="company"value="<?php echo $work['company_name']; ?>"><br>
                                <label for="file">Description:</label>
                                <input type="text" name="des" id="description"value="<?php echo $work['description']; ?>"><br>
                                <label for="file">Filename:</label>
                                <input type="file" name="file" id="file"><br>
                                <input type="submit" name="submit" value="Submit">
                            </form>
                            <?php
                            if (isset($_POST['submit'])) {
                                $allowedExts = array("gif", "jpeg", "jpg", "png");
                                $temp = explode(".", $_FILES["file"]["name"]);  //ten hinh va duoi file
                                $extension = end($temp); //hien cai duoi
                                if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && in_array($extension, $allowedExts)) {
                                    if ($_FILES["file"]["error"] > 0) {
                                        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
                                    } else {
                                        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
                                        echo "Type: " . $_FILES["file"]["type"] . "<br>";
                                        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
                                        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
                                        $file_name = $temp[0] . '-' . time() . '.' . $temp[1]; //upload cung luc ko loi
                                        if (file_exists("public/image/" . $_FILES["file"]["name"])) {
                                            echo $_FILES["file"]["name"] . " already exists. ";
                                        } else {
                                            move_uploaded_file($_FILES["file"]["tmp_name"], "public/image/" . $file_name);
                                            echo "Stored in: " . "public/image/" . $file_name . "</br>";
                                        }
                                        $array = array(
                                            "id" => $_GET["id"],
                                            "img" => "public/image/" . $file_name
                                        );
                                        $keyword->update($array);
                                        $url = "public/image/" . $file_name;
                                    }
                                } else {
                                    echo "Invalid file";
                                }
                                echo "<img src='$url ' width='150px'>";
                            }
                            ?>
                        </div>              
                        </div>
                    </section>
                    <div class="clear"></div>

                </header>
                <div class="clear"></div>
                <div id="boderaa"></div>
                <footer class="one">
                    <p class="colleft">
                    <table class="o">
                        <tr>
                            <td>1.</td><td>NGUYỄN HOÀNG ANH THIÊN</td></tr>
                        <tr><td>2.</td><td>HUỲNH THỊ BÍCH VÂN</td></tr>
                        <tr> <td>3.</td><td>ĐOÀN THANH TÂN</td></tr>

                    </table>
                    </p>
                    <p class="colright">
                    <table class="colright">
                        <tr>
                            <td></td><td>CONTACT</td></tr>
                        <tr><td></td><td>TRƯỜNG CAO ĐẲNG CÔNG NGHỆ THỦ ĐỨC</td></tr>
                        <tr> <td></td><td>Proudly powered by Drupal. Designed by C12TDT Works</td></tr>
                    </table>
                    </p>
                </footer>
            </div>
        </div>
    </body>
</html>
